< previous page page_183 next page >

Page 183
And, of course, you could also assign the values in the text boxes to variables and then pass them to the procedure:
9f31265bb40b592b1929e18a47ab28e5.gif
Private Sub cmdSave_Click()
   Dim strFirst As String
   Dim strLast As String

   strFirst = txtFirst.Text
   strLast = txtLast.Text

   EmployeeDisplay strFirst, strLast
   Call EmployeeDisplay(strFirst, strLast)
End Sub
Parameters in Functions
Functions can also be declared to accept arguments just like procedures. Heres the same EmployeeDisplay routine written now as a function that accepts arguments:
9f31265bb40b592b1929e18a47ab28e5.gif
Public Function EmployeeDisplay(strFirst As String, _
                             strLast As String) As String
   Dim strEmp As String

   strEmp = "My Last Name is " & strLast
   strEmp = strEmp & " and my first name is " & strFirst

   EmployeeDisplay = strEmp
End Function
Calling Functions with Parameters
To call this function, you still follow all the old rules. Youre just adding the ability to pass in the two parameters.
9f31265bb40b592b1929e18a47ab28e5.gif
Private Sub cmdSave_Click()
   Dim strName As String

   MsgBox EmployeeDisplay("Bill", "Gates")

   strName = EmployeeDisplay("Michael", "Gilbert")
   MsgBox strName
End Sub

 
< previous page page_183 next page >

If you like this book, buy it!